package config

import (
	"log"
	"net"
	"os"
	"os/user"
	"path"
	"runtime"
)

// StoryDir 故事路径
var StoryDir = "/home/root/userdata/story"

// TaskDir task
var TaskDir = "/home/root/userdata/task"

// TipsAudio TipsAudio
var TipsAudio = "/home/root/userdata/tipsAudio"

// MaxRepeatSearch 当一页找不到之后重复搜索的次数
const MaxRepeatSearch = 5

// DatabasePath 数据库所在的路径
var DatabasePath = "/home/root/userdata/storydb"

// MajorDB majordb
const MajorDB = "major.db"

// SlaveDB SlaveDB
const SlaveDB = "story.db"

// PageFlipFreq PageFlip 每秒钟拍照频率
const PageFlipFreq = 20

// GetFeatureRepeat 重复的获取页面特征值
const GetFeatureRepeat = 10

// Audio audiofiles
var Audio map[string]string

// BootAudio play after boot
var BootAudio = "/home/root/boot_music/boot.ogg"

// StoryDB storydb
var StoryDB = DatabasePath + "/story.db"

// MacAddress MacAddress
var MacAddress = ""

// BaseURL BaseURL
var BaseURL = os.Getenv("BASEURL")

// SearchFeature 搜索封面
var SearchFeature = BaseURL + "/api/devices" + MacAddress + "/search-book"

// OSSInfo ossinfo
var OSSInfo = map[string]string{
	"ossEndpoint":           "oss-cn-qingdao.aliyuncs.com",
	"aliyunAccessKeyId":     "CUnMQCZZ25CCZlRt",
	"aliyunAccessKeySecret": "ZuPdQZuWs61Ode2pv6246IEnPnot7r",
}

func init() {
	BaseURL = "http://test.bbcloud.com:7000"
	Audio = map[string]string{
		"unr_cover":           "unr_cover.ogg",           // 无法找到这本书
		"unr_page":            "unr_page.ogg",            // 无法识别书中的某一页
		"success_add_book":    "success_add_book.ogg",    // 成功添加一本书
		"recognising_page":    "recognising_page.ogg",    // 添加 cover 或者 page 的时候正在识别页面特征值
		"before_record":       "before_record.ogg",       // 录音开始的提示音
		"after_record":        "after_record.ogg",        // 录音结束的提示音
		"scanning_page_kacha": "scanning_page_kacha.ogg", // 在录音之前的相机模拟声音
		"scanning_page_di":    "scanning_page_di.ogg",    // 拍照的时候的时间模拟声音
	}
	for k, v := range Audio {
		Audio[k] = "/home/root/sysaudios/" + v
	}

	interfaces, _ := net.Interfaces()
	for _, inter := range interfaces {
		if inter.Name == "wlp3s0" {
			MacAddress = string(inter.HardwareAddr)
		}
	}
	if runtime.GOOS == "linux" && runtime.GOARCH == "amd64" {
		u, err := user.Lookup("tosone")
		if err != nil {
			log.Println(err)
			return
		}
		StoryDir = path.Join(u.HomeDir, "userdata/story")
		TaskDir = path.Join(u.HomeDir, "userdata/task")
		DatabasePath = path.Join(u.HomeDir, "userdata/storydb")
	}
}
